package com.treasuremall.auth.config;

import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

/**
 * 一句话描述功能
 *
 * @author 时前程
 * @create 2020-02-25 22:11
 * @Version V1.0
 **/
@Configuration
@AllArgsConstructor
@EnableResourceServer
public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {

    /**
     * 自定义登录成功处理器
     */
    private AuthenticationSuccessHandler appLoginInSuccessHandler;
    private AuthenticationFailureHandler appAuthenticationFailureHandler;
    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.headers().frameOptions().disable();
        http.formLogin()
                .loginProcessingUrl("/treasure/login")
                .successHandler(appLoginInSuccessHandler)
                .and()
                .authorizeRequests()
                .antMatchers("/user")
                .permitAll()
                .anyRequest().authenticated().and()
                .csrf().disable();
    }
}
